﻿Imports System.Windows.Forms.OpenFileDialog
Imports System.Object
Imports System.MarshalByRefObject
Imports System.ComponentModel.Component
Imports System.Windows.Forms.CommonDialog
Imports System.Windows.Forms



Public Class frmEmpleado
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub EmpleadosBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmpleadosBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.EmpleadosBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub frmEmpleado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.cargos' table. You can move, or remove it, as needed.
        Me.CargosTableAdapter.Fill(Me.DbFireAndIceDataSet.cargos)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)

    End Sub

    Private Sub XtraTabControl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XtraTabControl1.Click

    End Sub

    Private Sub IdempleadoLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()

    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()

    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                EmpleadosTableAdapter.DeleteQuery(IdempleadoTextBox.Text)
                Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
        If (NombreTextBox.Text.Length = 0) Then
            ErrorProvider1.SetError(NombreTextBox, "Debe ingresar un nombre")
        End If

        If (ApellidoTextBox.Text.Length = 0) Then
            ErrorProvider1.SetError(ApellidoTextBox, "Debe ingresar un apellido")

        End If
        If (SexoComboBox.Text.Length = 0) Then
            ErrorProvider1.SetError(SexoComboBox, "Debe selecionar una opción")
        End If
        If (EstadocivilComboBox.Text.Length = 0) Then
            ErrorProvider1.SetError(EstadocivilComboBox, "Debe serleccionar una opción")
        End If

        If (Telefono1TextBox.Text.Length = 0) Then
            ErrorProvider1.SetError(Telefono1TextBox, "Debe ingresar un telefono")
        End If


        If (IdcargoComboBox.Text.Length = 0) Then
            ErrorProvider1.SetError(IdcargoComboBox, "Debe ingresar un cargo")
        End If

        If (sueldobaseSpinEdit.Text.Length = 0) Then
            ErrorProvider1.SetError(sueldobaseSpinEdit, "Debe ingresar un sueldo base")




        Else


            ErrorProvider1.SetError(NombreTextBox, Nothing)
            ErrorProvider1.SetError(ApellidoTextBox, Nothing)
            ErrorProvider1.SetError(SexoComboBox, Nothing)
            ErrorProvider1.SetError(EstadocivilComboBox, Nothing)
            ErrorProvider1.SetError(Telefono1TextBox, Nothing)
            ErrorProvider1.SetError(IdcargoComboBox, Nothing)

            ErrorProvider1.SetError(sueldobaseSpinEdit, Nothing)
            EmpleadosBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If









        'Else
        '    ErrorProvider1.SetError(DescripcionTextBox, Nothing)

        '    If SalariopropuestoTextBox.Text.Length = 0 Then
        '        ErrorProvider1.SetError(SalariopropuestoTextBox, "Debe ingresar una cantidad")

        '    Else
        '        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        '        ErrorProvider1.SetError(SalariopropuestoTextBox, Nothing)

        '        CargosBindingNavigatorSaveItem.PerformClick()
        '        MessageBox.Show("Se guardó el resgistro satisfactoriamente")
        '        Mostrar()
        '    End If
        'End If
    End Sub

    Private Sub PanelArriba_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PanelArriba.Paint

    End Sub

    Private Sub XtraTabPage2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles XtraTabPage2.Paint

    End Sub


    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim openFile As New System.Windows.Forms.OpenFileDialog()
        Dim img As Byte

        openFile.DefaultExt = "Picture"
        openFile.Filter = "jpg (*.jpg)|*.jpg|png (*.png*)|*.png*"

        openFile.ShowDialog()
        If openFile.FileNames.Length > 0 Then
            Dim filename As String
            For Each filename In openFile.FileNames
                PictureBox2.Image = System.Drawing.Image.FromFile(openFile.FileName)
                PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage

                MsgBox(img)
            Next
        End If
    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(NombreTextBox, Nothing)
        ErrorProvider1.SetError(ApellidoTextBox, Nothing)
        ErrorProvider1.SetError(SexoComboBox, Nothing)
        ErrorProvider1.SetError(EstadocivilComboBox, Nothing)
        ErrorProvider1.SetError(Telefono1TextBox, Nothing)
        ErrorProvider1.SetError(IdcargoComboBox, Nothing)
        Mostrar()
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
    End Sub

    Private Sub IdcargoComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdcargoComboBox.SelectedIndexChanged

    End Sub
End Class